package view.mh;

import java.awt.Font;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import util.Config;

import java.applet.Applet;
import java.applet.AudioClip;
/**
 * 
 * 
 * @author Michael Hejna
 *@version 2.0
 */
public class CredWindow extends JApplet{

	private Sequencer sequencer;

	public CredWindow() {
		
		
	}
	
	public void credits(){
		
		
			sound();
			
			
			JFrame credits = new JFrame("Credits");
			
			JPanel credpanel = new JPanel();
			Font fc = new Font("Arial", Font.BOLD, 12);
			JTextArea creditlist = new JTextArea();
			creditlist.setFont(fc);
			creditlist.setText("This marvellous program was developed by the Alfatraining Genius Group.\n");
			creditlist.append("\nLead-Developer aka 'The One to blame': Sebastian Althof\n");
			creditlist.append("Project-Manager aka 'The Invisible': Thomas Görlitz\n");
			creditlist.append("\nGUI-Designers:\n");
			creditlist.append("Hansjörg Winterhalter aka 'The Robot-Man'\n");
			creditlist.append("Michael Hejna aka 'Mr Eye-Cancer'\n");
			creditlist.append("\nModel-Developer or 'The Ones who always get nagged':\n");
			creditlist.append("Jakobus Böttcher aka 'The Wizard at the Keyboard'\n");
			creditlist.append("Bernd Taube aka 'The Man with the Plan'\n");
			creditlist.append("Michael Metzger aka 'The Butcher'\n");
			creditlist.append("\nDatabase-Developer:\n");
			creditlist.append("Katharina Matei aka 'Mistress of the Datas'\n");
			creditlist.append("Jörg Bartels aka 'The Master of Queries'");
			creditlist.append("\n\nSpecial thanks go to:\n");
			creditlist.append("the nameless girl who always refilled the coffee machine!");
			creditlist.append("\n\n\n Please refer complains to Mr Althof and the cash to Mr Hejna. :-) ");
			creditlist.append("\n WE WILL BE BACK!!");
			creditlist.setEditable(false);
			
			credpanel.add(creditlist);
			credits.add(credpanel);
			credits.pack();
			credits.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			credits.addWindowListener(new WindowListener() {
				
				@Override
				public void windowOpened(WindowEvent arg0) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void windowIconified(WindowEvent arg0) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void windowDeiconified(WindowEvent arg0) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void windowDeactivated(WindowEvent arg0) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void windowClosing(WindowEvent arg0) {
					// TODO Auto-generated method stub
					sequencer.close();
				}
				
				@Override
				public void windowClosed(WindowEvent arg0) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void windowActivated(WindowEvent arg0) {
					// TODO Auto-generated method stub
					
				}
			});
			credits.setVisible(true);
			
			
			
			
		}
		
		/**
		 * 
		 * Pseudo-Easteregg
		 * 
		 * 
		 */
		public void sound(){
			 try {
			        // From file
			        Sequence sequence = MidiSystem.getSequence(new File(Config.APP_DIR + File.separator+"resources"+File.separator+"walkurenritt.mid"));
			    
			       
			    
			        sequencer = MidiSystem.getSequencer();
			        sequencer.open();
			        sequencer.setSequence(sequence);
			    
			        // Start playing
			        sequencer.start();
			    } catch (MalformedURLException e) {
			    } catch (IOException e) {
			    } catch (MidiUnavailableException e) {
			    } catch (InvalidMidiDataException e) {
			    }
			
			
		}
	
}
